import 'package:flutter/material.dart';
import 'package:flutter_widgets_pc/utils/toast_util.dart';

import '../../resources/l10n/kq_intl.dart';
import '../listener/kq_tap_gesture_listener.dart';

///该view提供判断是否有权限时按钮的透明度与无权限时点击的提示
class KqPermissionView extends StatelessWidget {
  /// 是否有权限
  final bool hasPermission;

  /// 当没有权限时的提示语
  final String? noPermissionNotice;

  /// 子view
  final Widget? child;

  /// 当没有权限时，子view的透明度
  final double noPermissionAlpha;

  const KqPermissionView({
    super.key,
    this.hasPermission = true,
    this.noPermissionNotice,
    this.noPermissionAlpha = 0.3,
    this.child,
  });

  @override
  Widget build(BuildContext context) {
    return KqTapGestureListener(
      onTap: () {
        if (!hasPermission) {
          KqToast.showNormal(
              noPermissionNotice ?? KqIntl.currentResource.noPermission);
        }
      },
      child: Opacity(
        opacity: hasPermission ? 1.0 : noPermissionAlpha,
        child: child,
      ),
    );
  }
}
